package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.Plan;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PlanService;

@Controller
@RequestMapping(value = "/plan")
public class PlanController {
	
	@Autowired
	private PlanService planService;

	@RequestMapping(value = "/operateByPlan")
	public @ResponseBody ResultBean operateByPlan(@RequestBody Plan plan) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (plan.getModificationFlag() == IModificationFlags.NEW) {
			return planService.save(plan);
			// Judge to update
		} else if (plan.getModificationFlag() == IModificationFlags.MODIFIED) {
			return planService.update(plan);
			// Judge to delete
		} else if (plan.getModificationFlag() == IModificationFlags.DELETED) {
			return planService.delete(plan);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/closePlan")
	public @ResponseBody ResultBean closePlan(@RequestBody Plan plan) {
		return planService.closePlan(plan);
	}

}
